<?php
require('conn.php');
require('functions.php');
require('session.php');
//print_r($session);
$is_pay=$_GET['is_pay'];
//修改资料
	if($_POST){
		//$wx=guolv(trim($_POST['wx']));
		//$pass=guolv(trim($_POST['pass']));
		$uid=guolv(trim($_POST['uid']));
		$realname=guolv(trim($_POST['realname']));
		$alipay=guolv(trim($_POST['alipay']));
		$phone=guolv(trim($_POST['phone']));
		$wx=guolv(trim($_POST['wx']));

		if($userdata['realname']!=='' && $userdata['alipay']!=='' && $userdata['phone']!==''){
			echo "<script>alert('收款姓名、支付宝、手机号，一经填写不得修改！');location.href='zl.php'</script>";
			exit;			
		}
		
		if($alipay=='' || $realname=='' || $phone==''){
			echo "<script>alert('请填写每一项内容，一经填写不得修改！');location.href='zl.php'</script>";
			exit;		
		}
		
		if(is_phone($phone)==false){
			echo "<script>alert('请输入正确的手机号');location.href='zl.php'</script>";
			exit;
		}

		$row=$mysql->query("select * from `userdata` where `alipay`='{$alipay}' limit 1");
		if($row){
			echo "<script>alert('支付宝已经被注册');location.href='zl.php'</script>";
			exit;
		}
		$mysql->execute("update `userdata` set `phone`='{$phone}',`alipay`='{$alipay}',`realname`='{$realname}',`wx`='{$wx}' where `id`='{$uid}'");
		if ($is_pay==1) {
			echo "<script>alert('填写成功，点击提现');location.href='tx.php'</script>";
			exit;
		}else{
			echo "<script>alert('填写成功，点击提现');location.href='zl.php'</script>";
			exit;
		}
		}

?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0" />
<title>用户资料</title>
<meta name="keywords" content="<?php echo $config['sitename']?>,用户资料" />
<meta name="description" content="<?php echo $config['sitename']?>用户资料">
<link href="<?php echo $site?>/static/all.css" type="text/css" rel="stylesheet" media="all">
<style>
td {
	border-bottom: 1px solid #ddd;
	line-height: 24px;
	font-size: 14px;
	color: #333;
	padding:5px 0;
}
/*.mhome{background:#fff;width: 100%;}*/
</style>
</head>

<body class="mhome">
<div style="width:100%;">
<div class="common-wrapper">
<p style="width:100%;font-size:18px;font-weight:bold;text-align:center;padding:10px;background-color:#f74545" class="clearfix">
<a style="width:50%;float:left;color:white;border-right: 1px solid white;" href="zl.php">用户资料</a>
<a style="width:50%;float:left;color:white;" href="editpwd.php">密码修改</a>
</p>

	<div class="main">
	<?php if ($is_pay==1): ?>
		<form action="zl.php?is_pay=1" method="post">
	<?php else: ?>
		<form action="zl.php" method="post">
	<?php endif; ?>
		<input type="hidden" value="<?php echo $session['id']?>" name="uid">
			<div class="item">
				<input value="<?php echo $userdata['phone']?>" class="txt-input txtpd" name="phone"  placeholder="手机号(必填)" type="text" />
			</div>
			<div class="item">
				<input value="<?php echo $userdata['realname']?>"  name="realname" class="txt-input txtpd" placeholder="收款姓名(必填)" type="text" />
			</div>
			<div class="item">
				<input value="<?php echo $userdata['alipay']?>"  name="alipay" class="txt-input txtpd" placeholder="支付宝(必填，用于提现，不可更改)" type="text" />
			</div>				
			<div class="item">
				<input value="<?php echo $userdata['wx']?>"  name="wx" class="txt-input txtpd" placeholder="微信号(选填)" type="text" />
			</div>			
			<!--
			<div class="item">
				<input style="width: 40%;" name="code" type="text" class="txt-input txtpd" placeholder="请输入验证码" />
				<img src="code.php?<?php echo rand(1,99)?>">
			</div>		
			-->
			<br>			
			<div class="item item-btns"> 
			<input type="submit" value="保存" class="btn-login">
			</div>
		</form>
		<div style="width:100%;text-align:right">
        	<a href="session.php?do=exit" style="font-size: 0.6em;">注销账号</a>
		</div>


	</div>
</div>
</div>
<?php
@session_start();
if(isset($_SESSION)){
	$_uid=$_SESSION['userdata']['id'];
}else{
	$_uid=guolv($_GET['uid']);
}
?>
<div class="positionFooter">
	<ul style="height:100%;">
		<li><a class="a4" href="<?php echo $site?>/ucenter.php"></a></li>   
		<li><a class="a2" href="<?php echo $site?>/list.php?uid=<?php echo $_uid?>"></a></li>
		<li><a class="a3" href="<?php echo $site?>/news.php?type=1"></a></li>
	</ul>
</div>

<?php
$mysql->__destruct();
$mysql->close();
?>
</body>
</html>
